home *** CD-ROM | disk | FTP | other *** search
- unit NewForms;
- {$R-,S-,I-,O-,F-,A+,U+,K+,W-,V+,B-,X+,T-,P+,L+,Y+,D-}
-
- interface
-
- uses
- WinTypes, WinProcs, Messages, Controls, Classes, Forms;
-
- type
- TNewForm = class(TForm)
- constructor Create (AOwner : TComponent); override;
- procedure CreateParams (var Params : TCreateParams); override;
- procedure FormKeyPress(Sender: TObject; var Key: Char); virtual;
- procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); virtual;
- procedure FormClose(Sender: TObject; var Action: TCloseAction); virtual;
- private
- { Private declarations }
- procedure WMGetMinMaxInfo( var Message :TWMGetMinMaxInfo ); message
- WM_GETMINMAXINFO;
- public
- { Public declarations }
- Set_Enter : Boolean; { Set to convert CR to TAB }
- Set_Max : Boolean; { Set and init following to fix max size }
- Max_Width,
- Max_Height : Word;
- Set_Min : Boolean; { Set and init following to fix min size }
- Min_Width,
- Min_Height : Word;
- Set_Pos : Boolean; { Set and init following to fix posn }
- Max_Left,
- Max_Top : Word;
- OldOnkeyPress : TKeyPressEvent;
- OldOnkeyDown : TKeyEvent;
- OldOnClose : TCloseEvent;
- FormVar : ^TForm; { set by Launch }
- end;
-
- type
- TFormClass = class of TNewForm;
- TFormPtr = ^TNewForm;
-
- { Launch a form if not already open , else un-minimise and bring to front }
- procedure Launch (LClass : TFormClass; var LForm);
-
- implementation
-
- constructor TNewForm.Create (AOwner : TComponent);
- begin
- inherited Create (AOwner);
-
- if Set_Enter
- then begin
- OldOnKeyPress := OnKeyPress;
- OnKeyPress := FormKeyPress;
- OldOnKeyDown := OnKeyDown;
- OnKeyDown := FormKeyDown;
- KeyPreview := TRUE;
- end;
-
- OldOnClose := OnClose;
- OnClose := FormClose;
- end;
-
- procedure TNewForm.CreateParams (var Params : TCreateParams);
- begin
- if Set_Max
- then begin
- Params.Width := Max_Width;
- Params.Height := Max_Height;
- end;
- inherited CreateParams (Params);
- end;
-
- procedure TNewForm.FormKeyPress(Sender: TObject; var Key: Char);
- begin
- case Key of
- #13 : begin
- PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);
- {SelectNext ( ActiveControl as tWinControl, True, True );}
- Key := #0;
- end;
- else begin
- if assigned (OldOnKeyPress)
- then OldOnKeyPress (Sender, Key);
- end;
- end;
- end;
-
- procedure TNewForm.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- case Key of
- Vk_Return : Key := Vk_Tab;
- else begin
- if assigned (OldOnKeyDown)
- then OldOnKeyDown (Sender, Key, Shift);
- end;
- end;
- end;
-
- procedure TNewForm.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- Application.OnHint := nil;
- if FormStyle = fsMdiChild
- then Action := caFree;
- if assigned (OldOnClose)
- then OldOnClose (Sender,Action);
- if assigned (FormVar)
- then FormVar^ := nil;
- end;
-
- procedure TNewForm.WMGetMinMaxInfo (var Message :TWMGetMinMaxInfo);
- begin
- with Message.MinMaxInfo^ do
- begin
- if Set_Max
- then begin
- if Max_Width <> 0
- then ptMaxSize.X := Max_Width; {Width when maximized.}
- if Max_Height <> 0
- then ptMaxSize.Y := Max_Height; {Height when maximized.}
- Message.Result := 0; {Tell windows you have changed minmaxinfo.}
- end;
- if Set_Pos
- then begin
- if Max_Left <> 0
- then ptMaxPosition.X := Max_Left; {Left position when maximized.}
- if Max_Top <> 0
- then ptMaxPosition.Y := Max_Top; {Top position when maximized.}
- Message.Result := 0; {Tell windows you have changed minmaxinfo.}
- end;
- if Set_Min
- then begin
- if Min_Width <> 0
- then ptMinTrackSize.X := Min_Width; {Minimum width.}
- if Min_Height <> 0
- then ptMinTrackSize.Y := Min_Height;{Minimum height.}
- Message.Result := 0; {Tell windows you have changed minmaxinfo.}
- end;
- if Set_Max
- then begin
- if Max_Width <> 0
- then ptMaxTrackSize.X := Max_Width; {Maximum width.}
- if Max_Height <> 0
- then ptMaxTrackSize.Y := Max_Height;{Maximum height.}
- end;
- end;
- inherited;
- end;
-
- procedure Launch (LClass : TFormClass; var LForm);
- var
- LNewForm : TNewForm absolute LForm;
- begin
- if LNewForm = nil
- then begin
- Application.CreateForm (LClass,LNewForm);
- LNewForm.FormVar := @LNewForm;
- end
- else with LNewForm
- do begin
- BringToFront;
- If WindowState = wsMinimized
- then WindowState := wsNormal;
- end;
- end;
-
- end.
-